#!/usr/bin/env python
#coding:utf8

import man
import time
import datetime
import bank
import mall
from prettytable import PrettyTable 

def admin():
    user_dict = bank.read_user_data()
    while True:
        list1 = ['用户状态','触发账单日','用户解锁','账单']
        for index,v in enumerate(list1):
            print '\033[32m%s : %s\033[0m' % (index,v)
        user_input = raw_input('请输入ID (Q\q 退出)： ').strip()
        if user_input == '0': #状态信息
            user_dict = bank.read_user_data()
            list1 = ['名称','状态','信用额度','欠款金额']
            pt = PrettyTable(list1)
            for i in user_dict.items():
                pt.add_row([i[0],i[1]['status'],i[1]['credit'],i[1]['overdraft']])
            print pt
        elif user_input == '1':#触发账单日
            date_now = datetime.datetime.now()
            for i in user_dict.items(): 
                i[1]['bill'][date_now] = [i[1]['overdraft'],'月底还款账单']
            bank.write_data(user_dict)
            time.sleep(1)
            print '\033[33madmin 触发账单日成功 \n \033[0m'
        elif user_input == '2':#用户解锁
            user_input = raw_input('\033[32m请输入需要解锁的用户名:\033[0m').strip()
            if user_input in user_dict:
                user_dict[user_input]['status'] = 'ok'
                bank.write_data(user_dict)
            else:
                print '\033[31m您输入的用户不存在 \n \033[0m'
        elif user_input == '3':
            pt = PrettyTable(['日期','金额','类型'])
            list1 = user_dict['admin']['bill']
            for k,v in list1.items():
                pt.add_row([k,v[0],v[1]])
            print pt
        elif user_input == 'Q' or user_input == 'q':
            print '\033[31m正在安全退出\n \033[0m'
            time.sleep(1)
            man.man1()



if __name__ == '__main__':
    admin()




